<template>
  <div id="tab-bar-item" @click="itemClick">
    <div class="item-icon" v-show="!isActive"><slot name="icon"></slot></div>
    <div class="item-active-icon" v-show="isActive"><slot name="active-icon"></slot></div>
    <div class="item-text" :style="activeStyle"><slot name="text"></slot></div>
    <div class="item-center"><slot name="center"></slot></div>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  props: {
    link: {
      type: String,
      required: true
    }
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.link) !== -1
    },
    activeStyle() {
      return this.isActive ? {'color': '#FF5543'} : {}
    }
  },
  methods: {
    itemClick() {
      this.$router.replace(this.link)
    }
  }
}
</script>

<style lang="less" scoped>
  #tab-bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .item-icon {
    width: .533333rem;
    height: .533333rem;
    margin-top: .2rem;
    margin-bottom: .133333rem; 
     img {
       display: block;
       width: .533333rem;
       height: .533333rem;
     }
  }

  .item-active-icon {
    width: .533333rem;
    height: .533333rem;
    margin-top: .2rem;
    margin-bottom: .133333rem; 
     img {
       display: block;
       width: .533333rem;
       height: .533333rem;
     }
  }

  .item-text {
    font-size: .266667rem;
    font-weight: 500;
    color: #999999;
  }
</style>